import Mock from 'mockjs';
import { menuListByAdmin, menuListByEmployee } from './data';

/** mock配置 */
Mock.setup({ timeout: '200-600' });

/** 登录接口 */
Mock.mock('https://www.demo.com/login', 'post', (options: any) => {
  const { username, password } = JSON.parse(options.body);

  if (username === 'admin' && password === '123321') {
    return {
      code: 200,
      message: '登录成功',
      data: {
        token: 'admintokenkkljbuo2w9xla2',
        user: {
          username: '赖军',
          roles: ['amdin'],
        },
        menuList: menuListByAdmin,
      },
    };
  }

  if (username === 'user' && password === '123321') {
    return {
      code: 200,
      message: '登录成功',
      data: {
        token: 'usertokenlkg55dws5ch4ew97cl',
        user: {
          username: '江霞',
          roles: ['user'],
        },
        menuList: menuListByEmployee,
      },
    };
  }

  return {
    code: 401,
    message: '用户名或密码错误',
  };
});
